home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / D-G / FORTRAN Goodies / QuickTime Folder / ImageCompression.f < prev    next >
Encoding:
Text File  |  1992-10-23  |  16.8 KB  |  437 lines  |  [TEXT/MPS ]

  1.  
  2. c    Created: Tuesday, August 13, 1991 at 4:31 PM
  3. c     ImageCompression.p
  4. c     Pascal Interface to the Macintosh Libraries
  5.     
  6. c     Copyright Apple Computer, Inc. 1991
  7. c     All rights reserved
  8.     
  9.     
  10.     
  11. !!IFC UNDEFINED UsingIncludes
  12. !!SETC UsingIncludes = False
  13. !!ENDC
  14.     
  15. !!IFC NOT UsingIncludes
  16. !!I ZEROINC.F
  17. !!ENDC
  18.  
  19. !!IFC NOT GotImageCompression
  20. !!SETC GotImageCompression = True
  21.     
  22. !!IFC Not GotQuickDraw
  23. !!I QuickDraw.f
  24. !!ENDC
  25. !!IFC not GotQDOffscreen
  26. !!I QDOffscreen.f
  27. !!ENDC
  28. !!IFC not GotTypes
  29. !!I Types.f
  30. !!ENDC
  31. !!IFC not GotComponents
  32. !!I Components.f
  33. !!ENDC
  34. !!IFC not GotStandardFile
  35. !!I StandardFile.f
  36. !!ENDC
  37.     
  38.     Character*4 gestaltCompressionMgr
  39.     Parameter (gestaltCompressionMgr = 'icmp')
  40.     
  41. c These are the bits that are set in the Component flags, and also in the codecInfo struct. 
  42.     
  43.     Integer*4 codecInfoDoes1  
  44.     Integer*4 codecInfoDoes2  
  45.     Integer*4 codecInfoDoes4  
  46.     Integer*4 codecInfoDoes8  
  47.     Integer*4 codecInfoDoes16  
  48.     Integer*4 codecInfoDoes32  
  49.     Integer*4 codecInfoDoesDither  
  50.     Integer*4 codecInfoDoesStretch  
  51.     Integer*4 codecInfoDoesShrink  
  52.     Integer*4 codecInfoDoesMask  
  53.     
  54.     Integer*4 codecInfoDoesTemporal  
  55.     
  56.     Integer*4 codecInfoDoesDouble  
  57.     Integer*4 codecInfoDoesQuad  
  58.     Integer*4 codecInfoDoesHalf  
  59.     Integer*4 codecInfoDoesQuarter  
  60.     
  61.     Integer*4 codecInfoDoesRotate  
  62.     Integer*4 codecInfoDoesHorizFlip  
  63.     Integer*4 codecInfoDoesVertFlip  
  64.     Integer*4 codecInfoDoesSkew  
  65.     Integer*4 codecInfoDoesBlend  
  66.     Integer*4 codecInfoDoesWarp 
  67.     Integer*4 codecInfoDoesRecompress 
  68.     Integer*4 codecInfoDoesSpool 
  69.     
  70.     Parameter (codecInfoDoes1 = $1)            ! codec can work with 1-bit pixels 
  71.     Parameter (codecInfoDoes2 = $2)            ! codec can work with 2-bit pixels 
  72.     Parameter (codecInfoDoes4 = $4)            ! codec can work with 4-bit pixels 
  73.     Parameter (codecInfoDoes8 = $8)            ! codec can work with 8-bit pixels 
  74.     Parameter (codecInfoDoes16 = $10)        ! codec can work with 16-bit pixels 
  75.     Parameter (codecInfoDoes32 = $20)        ! codec can work with 32-bit pixels 
  76.     Parameter (codecInfoDoesDither = $40)    ! codec can do ditherMode 
  77.     Parameter (codecInfoDoesStretch = $80)    ! codec can stretch to arbitrary sizes 
  78.     Parameter (codecInfoDoesShrink = $100)    ! codec can shrink to arbitrary sizes 
  79.     Parameter (codecInfoDoesMask = $200)    ! codec can mask to clipping regions 
  80.     
  81.     Parameter (codecInfoDoesTemporal = $400)! codec can handle temporal redundancy 
  82.     
  83.     Parameter (codecInfoDoesDouble = $800)    ! codec can stretch to double size exactly 
  84.     Parameter (codecInfoDoesQuad = $1000)    ! codec can stretch to quadruple size exactly 
  85.     Parameter (codecInfoDoesHalf = $2000)    ! codec can shrink to half size 
  86.     Parameter (codecInfoDoesQuarter = $4000)! codec can shrink to quarter size 
  87.     
  88.     Parameter (codecInfoDoesRotate = $8000)    ! codec can rotate on decompress 
  89.     Parameter (codecInfoDoesHorizFlip = $10000)    ! codec can flip horizontally on decompress 
  90.     Parameter (codecInfoDoesVertFlip = $20000)    ! codec can flip vertically on decompress 
  91.     Parameter (codecInfoDoesSkew = $40000)    ! codec can skew on decompress 
  92.     Parameter (codecInfoDoesBlend = $80000)    ! codec can blend on decompress 
  93.     Parameter (codecInfoDoesWarp = $100000)    ! codec can warp arbitrarily on decompress 
  94.     Parameter (codecInfoDoesRecompress = $200000)! codec can recompress image without accumulating errors 
  95.     Parameter (codecInfoDoesSpool = $400000)! codec can spool image data 
  96.     
  97.     Integer*4  codecInfoDepth1  
  98.     Integer*4  codecInfoDepth2  
  99.     Integer*4  codecInfoDepth4  
  100.     Integer*4  codecInfoDepth8  
  101.     Integer*4  codecInfoDepth16  
  102.     Integer*4  codecInfoDepth32  
  103.     Integer*4  codecInfoDepth24  
  104.     Integer*4  codecInfoDepth33  
  105.     Integer*4  codecInfoDepth34  
  106.     Integer*4  codecInfoDepth36  
  107.     Integer*4  codecInfoDepth40  
  108.     Integer*4  codecInfoStoresClut  
  109.     Integer*4  codecInfoDoesLossless  
  110.  
  111.     Parameter (codecInfoDepth1 = $1) ! compressed data at 1 bpp depth available 
  112.     Parameter (codecInfoDepth2 = $2) ! compressed data at 2 bpp depth available 
  113.     Parameter (codecInfoDepth4 = $4) ! compressed data at 4 bpp depth available 
  114.     Parameter (codecInfoDepth8 = $8) ! compressed data at 8 bpp depth available 
  115.     Parameter (codecInfoDepth16 = $10) ! compressed data at 16 bpp depth available 
  116.     Parameter (codecInfoDepth32 = $20) ! compressed data at 32 bpp depth available 
  117.     Parameter (codecInfoDepth24 = $40) ! compressed data at 24 bpp depth available 
  118.     Parameter (codecInfoDepth33 = $80) ! compressed data at 1 bpp monochrome depth  available 
  119.     Parameter (codecInfoDepth34 = $100) ! compressed data at 2 bpp grayscale depth available 
  120.     Parameter (codecInfoDepth36 = $200) ! compressed data at 4 bpp grayscale depth available 
  121.     Parameter (codecInfoDepth40 = $400) ! compressed data at 8 bpp grayscale depth available 
  122.     Parameter (codecInfoStoresClut = $800) ! compressed data can have custom cluts 
  123.     Parameter (codecInfoDoesLossless = $1000) ! compressed data can be stored in lossless format 
  124.     
  125.     Integer*4 codecFlagUseImageBuffer 
  126.     Integer*4 codecFlagUseScreenBuffer  
  127.     Integer*4 codecFlagUpdatePrevious  
  128.     Integer*4 codecFlagNoScreenUpdate  
  129.     Integer*4 codecFlagWasCompressed  
  130.     Integer*4 codecFlagDontOffscreen  
  131.     Integer*4 codecFlagUpdatePreviousComp  
  132.     Integer*4 codecFlagForceKeyFrame  
  133.     Integer*4 codecFlagOnlyScreenUpdate  
  134.     Integer*4 codecFlagLiveGrab     
  135.     
  136.     Parameter (codecFlagUseImageBuffer = $1) ! (input) allocate buffer for whole image on decompress sequence 
  137.     Parameter (codecFlagUseScreenBuffer = $2) ! (input) allocate buffer for screen on decompress sequence for faster updates 
  138.     Parameter (codecFlagUpdatePrevious = $4) ! (input) udate previous buffer on compress sequence 
  139.     Parameter (codecFlagNoScreenUpdate = $8) ! (input) dont update screen, but do update image buffer If (allocated 
  140.     Parameter (codecFlagWasCompressed = $10) ! (input) hint to compressor that image was previously compressed 
  141.     Parameter (codecFlagDontOffscreen = $20) ! (input) return error instead of automatically going offscreen 
  142.     Parameter (codecFlagUpdatePreviousComp = $40) ! (input) udate previous buffer on compress sequence 
  143.     Parameter (codecFlagForceKeyFrame = $80) ! (input) when sent to CompressSequenceFrame, forces that frame to be a key frame 
  144.     Parameter (codecFlagOnlyScreenUpdate = $100) ! (input) only update screen from 
  145.     Parameter (codecFlagLiveGrab    = $200) ! (input) data being compressed is from live source (speed is critical) 
  146.         
  147.     Integer*4 codecFlagUsedNewImageBuffer     
  148.     Integer*4 codecFlagUsedImageBuffer  
  149.     
  150.     Parameter (codecFlagUsedNewImageBuffer    = $4000) ! (output) indicates that image buffer was first used on this decompress sequence 
  151.     Parameter (codecFlagUsedImageBuffer = $8000) ! (output) indicates that image buffer was used on this decompress sequence 
  152.  
  153.     Integer*2  codecErr  
  154.     Integer*2  noCodecErr  
  155.     Integer*2  codecUnimpErr  
  156.     Integer*2  codecSizeErr  
  157.     Integer*2  codecScreenBufErr  
  158.     Integer*2  codecImageBufErr  
  159.     Integer*2  codecSpoolErr  
  160.     Integer*2  codecAbortErr  
  161.     Integer*2  codecWouldOffscreenErr  
  162.     Integer*2  codecBadDataErr  
  163.     Integer*2  codecDataVersErr  
  164.     Integer*2  codecConditionErr  
  165.     Integer*2  codecOpenErr  
  166.     
  167.     Parameter (codecErr = -8960    ) ! the codec returned an error 
  168.     Parameter (noCodecErr = -8961) ! the specified codec could not be found 
  169.     Parameter (codecUnimpErr = -8962) ! this feature is not implemented by the specified codec 
  170.     Parameter (codecSizeErr = -8963)
  171.     Parameter (codecScreenBufErr = -8964) ! the screen buffer could not be allocated 
  172.     Parameter (codecImageBufErr = -8965) ! the image buffer could not be allocated 
  173.     Parameter (codecSpoolErr = -8966) ! the compressed data must be in memory (spooling did not work) 
  174.     Parameter (codecAbortErr = -8967) ! the operation was aborted by the progress proc 
  175.     Parameter (codecWouldOffscreenErr = -8968) ! an offscreen access would have been used, but wasn't allowed because codecFlagDontOffscreen was set 
  176.     Parameter (codecBadDataErr = -8969) ! compressed data was found to have inconsistencies 
  177.     Parameter (codecDataVersErr = -8970) ! compressed data was of a format version that codec couldn't handle 
  178.     Parameter (codecConditionErr = -8972) ! codec can not do requested operation 
  179.     Parameter (codecOpenErr = -8973    ) ! the codec  could not be opened 
  180.     
  181.     Integer*2  codecMinimumDataSize  
  182.     
  183.     Character*4 compressorComponentType  
  184.     Character*4 decompressorComponentType  
  185.     
  186.     Parameter (codecMinimumDataSize = 32768) ! The minimum data size for spooling in or out data 
  187.     
  188.     Parameter (compressorComponentType = 'imco') ! the type for "Components" which compress images 
  189.     Parameter (decompressorComponentType = 'imdc') ! the type for "Components" which decompress images 
  190.     
  191.     Integer*2 codecLosslessQuality    
  192.     Integer*2 codecMaxQuality            
  193.     Integer*2 codecMinQuality            
  194.     Integer*2 codecLowQuality            
  195.     Integer*2 codecNormalQuality        
  196.     Integer*2 codecHighQuality        
  197.     
  198.     Parameter (codecLosslessQuality    = $400)
  199.     Parameter (codecMaxQuality            = $3FF)
  200.     Parameter (codecMinQuality            = $000)
  201.     Parameter (codecLowQuality            = $100)
  202.     Parameter (codecNormalQuality        = $200)
  203.     Parameter (codecHighQuality        = $300)
  204.     
  205.     Integer*2 anyCodec                 
  206.     Integer*2 bestSpeedCodec             
  207.     Integer*2 bestFidelityCodec        
  208.     Integer*2 bestCompressionCodec    
  209.     
  210.     Parameter (anyCodec                 =  0)        ! take first working codec of given type 
  211.     Parameter (bestSpeedCodec             = -1)        ! take fastest codec of given type 
  212.     Parameter (bestFidelityCodec        = -2)        ! take codec which is most accurate
  213.     Parameter (bestCompressionCodec    = -3)            ! take codec of given type that is most accurate 
  214.     
  215.     Integer*2 codecCompletionSource 
  216.     Integer*2 codecCompletionDest 
  217.     
  218.     Integer*2 codecProgressOpen 
  219.     Integer*2 codecProgressUpdatePercent 
  220.     Integer*2 codecProgressClose 
  221.     
  222.     Parameter (codecCompletionSource = 1)            ! asynchronous codec is done with source data  
  223.     Parameter (codecCompletionDest = 2)                ! asynchronous codec is done with destination data  
  224.     
  225.     Parameter (codecProgressOpen = 0)
  226.     Parameter (codecProgressUpdatePercent = 1)
  227.     Parameter (codecProgressClose = 2)
  228.     
  229.     Integer*2 identityMatrixType            
  230.     Integer*2 translateMatrixType        
  231.     Integer*2 scaleMatrixType            
  232.     Integer*2 scaleTranslateMatrixType    
  233.     Integer*2 linearMatrixType            
  234.     Integer*2 linearTranslateMatrixType    
  235.     Integer*2 perspectiveMatrixType        
  236.  
  237.     Integer*2 sfpItemPreviewAreaUser 
  238.     Integer*2 sfpItemPreviewStaticText 
  239.     Integer*2 sfpItemPreviewDividerUser 
  240.     Integer*2 sfpItemCreatePreviewButton 
  241.     Integer*2 sfpItemShowPreviewButton 
  242.         
  243.     Parameter (identityMatrixType        = $00) ! result If (matrix is identity 
  244.     Parameter (translateMatrixType        = $01) ! result If (matrix translates 
  245.     Parameter (scaleMatrixType            = $02) ! result If (matrix scales 
  246.     Parameter (scaleTranslateMatrixType    = $03) ! result If (matrix scales and translates 
  247.     Parameter (linearMatrixType            = $04) ! result If (matrix is general 2 x 2 
  248.     Parameter (linearTranslateMatrixType = $05) ! result If (matrix is general 2 x 2 and translates 
  249.     Parameter (perspectiveMatrixType    = $06) ! result If (matrix is general 3 x 3 
  250.  
  251.     Parameter (sfpItemPreviewAreaUser = 11)
  252.     Parameter (sfpItemPreviewStaticText = 12)
  253.     Parameter (sfpItemPreviewDividerUser = 13)
  254.     Parameter (sfpItemCreatePreviewButton = 14)
  255.     Parameter (sfpItemShowPreviewButton = 15)
  256.         
  257.     
  258. c    CompressorComponent = Component        ! a Component which compresses images 
  259. c    DecompressorComponent = Component    ! a Component which decompresses images 
  260. c    CodecComponent = Component            ! a Component which decompresses or compresses images 
  261.  
  262. c    The following types are equivalent    
  263. c    sBoolean is the same as INTEGER*2        ! to make sure stack frames are right     
  264. c    CodecType is the same as OSTYPE            ! type descriptor for codecs i.e: 'appl','jpeg','rle '     
  265. c    CodecFlags is the same as INTEGER*2        ! flags for codec manager calls 
  266.     
  267. c    CodecQ is the same as Integer*4
  268. c    DataProcPtr is the same as ProcPtr
  269. c    FlushProcPtr is the same as ProcPtr
  270. c    CompletionProcPtr is the same as ProcPtr
  271. c    ProgressProcPtr is the same as ProcPtr
  272. c    ImageSequence is the same as Integer*4 
  273. c     MatrixFlags = CHAR
  274.     
  275.     
  276.     Structure /ProgressProcRecord/
  277.         Record /ProcPtr/ progressProc
  278.         Integer*4 progressRefCon
  279.     End Structure
  280.  
  281.     Structure /ProgressProcRecordPtr/
  282.         pointer /ProgressProcRecord/ P
  283.     End Structure
  284.  
  285.     Structure /CompletionProcRecord/
  286.         Record /ProcPtr/ completionProc
  287.         Integer*4 completionRefCon
  288.     End Structure
  289.  
  290.     Structure /CompletionProcRecordPtr/
  291.         pointer /CompletionProcRecord/ P
  292.     End Structure
  293.  
  294.     Structure /DataProcRecord/
  295.         Record /ProcPtr/ dataProc
  296.         Integer*4 dataRefCon
  297.     End Structure
  298.  
  299.     Structure /DataProcRecordPtr/
  300.         pointer /DataProcRecord/ P
  301.     End Structure
  302.  
  303.     Structure /FlushProcRecord/
  304.         Record /ProcPtr/ flushProc
  305.         Integer*4 flushRefCon
  306.     End Structure
  307.  
  308.     Structure /FlushProcRecordPtr/
  309.         pointer /FlushProcRecord/ P
  310.     End Structure
  311.  
  312. c    The ImageDescription is private data which is produced when an image or sequence 
  313. c    is compressed. It fully describes the format of the compressed data.
  314.     
  315.     Structure /ImageDescription/
  316.         Integer*4  idSize                ! total size of ImageDescription including extra data ( CLUTs and other per sequence data 
  317.         Record /OSType/ cType        ! what kind of codec compressed this data 
  318.         Integer*4  resvd1                ! reserved for apple use 
  319.         Integer*2  resvd2                ! reserved for apple use 
  320.         Integer*2  dataRefIndex            ! set to zero 
  321.         Integer*2  version                ! which version is this data 
  322.         Integer*2  revisionLevel        ! what version of that codec did this 
  323.         Integer*4 vendor                ! whose  codec compressed this data 
  324.          Integer*4 temporalQuality    ! what was the temporal quality factor          
  325.         Integer*4 spatialQuality    ! what was the spatial quality factor          
  326.         Integer*2  width                ! how many pixels wide is this data 
  327.         Integer*2  height                ! how many pixels high is this data 
  328.         Integer*4 hRes                    ! horizontal resolution 
  329.         Integer*4 vRes                    ! vertical resolution 
  330.         Integer*4 dataSize                ! If known, the size of data for this image descriptor 
  331.         Integer*2  frameCount            ! number of frames this description applies to 
  332.         Character*1 name(0:31)            ! name of codec ( in case not installed ) 
  333.         Integer*2  depth                ! what depth is this data (1-32) or ( 33-40 grayscale ) 
  334.         Integer*2  clutID                ! clut id or If (0 clut follows  or -1 If (no clut 
  335.     End Structure
  336.  
  337.     Structure /ImageDescriptionPtr/
  338.         pointer /ImageDescription/ P
  339.     End Structure
  340.  
  341.     Structure /ImageDescriptionHandle/
  342.         pointer /ImageDescriptionPtr/ H
  343.     End Structure
  344.  
  345. c    The codecInfo is the information returned as the codecInfo struct by a codec Component
  346. c    to the codec manager or to the caller. It is specific to the particular codec
  347. c   implementation and not to the codec type.
  348.     
  349.     Structure /codecInfo/
  350.      Character*1 typename(0:31)        ! name of the codec type i.e.: 'Apple Image Compression' 
  351.      Integer*2  version                ! version of the codec data that this codec knows about 
  352.      Integer*2  revisionLevel        ! revision level of this codec i.0x00010001 e: (1.0.1) 
  353.      Integer*4 vendor                ! Maker of this codec i. e: appl' 
  354.      Integer*4 decompressFlags        ! Parameter (codecInfo flags for decompression capabilities 
  355.      Integer*4 compressFlags        ! Parameter (codecInfo flags for compression capabilities 
  356.      Integer*4 formatFlags            ! Parameter (codecInfo flags for compression format details 
  357.      BYTE compressionAccuracy        ! measure (1-255) of accuracy of this codec for compress (0 If (unknown) 
  358.      BYTE decompressionAccuracy        ! measure (1-255) of accuracy of this codec for decompress (0 If (unknown) 
  359.      Integer*2  compressionSpeed    ! ( millisecs for compressing 320x240 on base mac II) (0 If (unknown) 
  360.      Integer*2  decompressionSpeed    ! ( millisecs for decompressing 320x240 on mac II)(0 If (unknown) 
  361.      Byte compressionLevel            ! measure (1-255) of compression level of this codec (0 If (unknown) 
  362.      Byte resvd                        ! pad 
  363.      Integer*2  minimumHeight        ! minimum height of image (block size) 
  364.      Integer*2  minimumWidth        ! minimum width of image (block size) 
  365.      Integer*2  decompressPipelineLatency! in milliseconds ( for asynchronous codecs ) 
  366.      Integer*2  compressPipelineLatency    ! in milliseconds ( for asynchronous codecs ) 
  367.      Integer*4 privateData
  368.     End Structure
  369.     
  370.     Structure /DitherTable/    ! Table used for fast dithering. 
  371.      Integer*4 tag
  372.      Integer*4 seed
  373.      Integer*4 reserved
  374.      Byte data(0:0)
  375.     End Structure
  376.  
  377.     Structure /DTabPtr/
  378.         pointer /DitherTable/ P
  379.     End Structure
  380.  
  381.     Structure /DTabHandle/
  382.         pointer /DTabPtr/ H
  383.     End Structure
  384.     
  385.     Structure /CodecNameSpec/    ! Name list returned by GetCodecNameList.
  386.         Record /Component/ codec
  387.         Record /OSType/ cType
  388.         Character*1 typeName(0:31)
  389.         Record /Handle/ name 
  390.     End Structure
  391.     
  392.     Structure /CodecNameSpecList/
  393.      Integer*2 count
  394.      Record /CodecNameSpec/ list(0:0)
  395.     End Structure
  396.  
  397.     Structure /CodecNameSpecListPtr/
  398.         pointer /CodecNameSpecList/ P
  399.     End Structure
  400.  
  401.     Structure /MatrixRecord/    !  Matrix stuff 
  402.      Integer*4 matrix(0:2,0:2)
  403.     End Structure
  404.  
  405.     Structure /MatrixRecordPtr/
  406.         pointer /MatrixRecord/ P
  407.     End Structure
  408.  
  409.     Structure /FixedPoint/
  410.      Integer*4 x
  411.      Integer*4 y
  412.     End Structure
  413.  
  414.     Structure /FixedRect/
  415.      Integer*4  left
  416.      Integer*4 top
  417.      Integer*4 right
  418.      Integer*4 bottom
  419.     End Structure
  420.  
  421.     Structure /PreviewResourceRecord/
  422.         Integer*4 modDate
  423.         Integer*2 version
  424.         RECORD /OSType/ resType
  425.         Integer*2 resID
  426.     End Structure
  427.  
  428.     Structure /PreviewResourcePtr/
  429.         pointer /PreviewResourceRecord/ P
  430.     End Structure
  431.  
  432.     Structure /PreviewResourceHandle/
  433.         pointer /PreviewResourcePtr/ H
  434.     End Structure
  435.     
  436. !!ENDC ! GotImageCompression 
  437.